<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用图书管理系统</title>
    <link href="css/admin.css" rel="stylesheet">
    <link rel="stylesheet" href="css/admin.css">
</head>
<body >
<h1 class="title">&nbsp&nbsp用户管理</h1>
<div class="navigate">
    <ul>
        <li><a href="admin_1.html" class="a1">图书管理员</a></li>
        <li><a href="admin_2.html" class="a2">普通用户</a></li>
        <li class="exit"><a href="login.html">退出登录</a></li>
    </ul>
</div>
<div>
    <input id="input_search" type="text" placeholder="搜索用户名" class="inp_search">
    <button id="button_search" type="button" class="btn_search">&nbsp</button>
</div>
<div>
    <div id="mainContent"></div>
</div>
</body>
<script src="js/jquery.js"></script>
<script src="js/admin.js"></script>
<script>
    $(document).ready(function () {
        var pageNum=1;
        var token=sessionStorage.getItem("token");
        console.log(token);
        $("#button_search").click(function (){
            //alert("ok");
            var username=$("#input_search").val();
            console.log(username);
            console.log("type:"+typeof username);
            $.ajax({
                url:"http://47.100.90.111:9090/admin/findUser?username="+username,
                type: "GET",
                headers: {
                    "Content-Type": "application/json;charset=utf8",
                    'Accept': '*/*',
                    "token":token
                },
                dataType: "json",
                success:function (data){
                    var obj=data.data;
                    if(obj!=null){
                        var str_enabled;
                        if(obj.id) {
                            str_enabled = "是";
                        }
                        else {
                            str_enabled="否";
                        }
                        var show=[];
                        show.push("<table class='table'>");
                        show.push("<thead><tr style='background-color: white;color: #457077;font-size: 18px'><td style='width: 250px'>用户名</td><td width='250px'>昵称</td><td>是否启用</td><td width='300px'>&nbsp</td></tr></thead><tbody>");
                        show.push("<tr>");
                        show.push("<td width='250px'>"+obj.username+"</td>");
                        show.push("<td width='250px'>"+obj.nickname+"</td>");
                        show.push("<td width='300px'>"+str_enabled+"</td>");
                        show.push("</tr>");
                        show.push("</tbody></table>");
                        var mainobj=$("#mainContent");
                        mainobj.empty();
                        mainobj.html(show.join(""));
                    }
                    else {
                        alert("查无此人！");
                    }
                },
                error:function (){
                    console.log("error");
                }
            })
        })
        $.ajax({
            url: "http://47.100.90.111:9090/admin/userList",
            type: "GET",
            //async:false,
            //cache:false,
            headers: {
                "Content-Type": "application/json;charset=utf8",
                'Accept': '*/*',
                "token":token
            },
            dataType: "json",
            success: function (data) {
                var obj=data.data.list;
                var show=[];
                show.push("<table class='table'>");
                show.push("<thead><tr style='background-color: white;color: #457077;font-size: 18px'><td style='width: 250px'>用户名</td><td width='250px'>昵称</td><td width='300px'>是否启用</td><td width='300px'>&nbsp</td></tr></thead><tbody>")
                for(var i=0;i<data.data.total;i++){//total
                    var str_enabled;
                    if(obj[i].id) {
                        str_enabled = "是";
                    }
                    else {
                        str_enabled="否";
                    }
                    show.push("<tr>");
                    show.push("<td width='250px'>"+obj[i].username+"</td>");
                    show.push("<td width='250px'>"+obj[i].nickname+"</td>");
                    show.push("<td width='300px'>"+str_enabled+"</td>");
                    show.push("</tr>");
                }
                show.push("</tbody></table>");
                var mainobj=$("#mainContent");
                mainobj.empty();
                mainobj.html(show.join(""));
            },
            error: function () {
                console.log('Request Error.');
            }
        });
    });
</script>
</html>